package live.jialing.sip.contact.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import live.jialing.core.beanvalidator.First;
import live.jialing.core.beanvalidator.Second;
import live.jialing.data.core.JpaDomainEntity;
import live.jialing.structure.domain.Employee;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.validator.constraints.NotBlank;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 通讯录中的分组
 */
@Setter
@Getter
@ToString
@Entity
@Table(name = "contact_group")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "contact_category", discriminatorType = DiscriminatorType.STRING, length = 30)
@DiscriminatorValue("normal")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = ContactGroup.class)
public abstract class ContactGroup extends JpaDomainEntity<Long> {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(message = "id不能为空", groups = {Second.class})
    private Long id;

    /**
     * 组的名称
     */
    @NotBlank(message = "名称不能为空", groups = {First.class, Second.class})
    private String name;

    /**
     * 组的所有者
     */
    @ManyToOne( fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "ower_user_id",updatable = false)
    private Employee ower;



}
